﻿using System;
using Samurai.DAL;
using Samurai.Infrastructure;
using System.Collections.ObjectModel;
using System.Windows.Input;

using System.Linq;

namespace Samurai.Client.Commands
{
    public class RefreshMoviesCommand : ICommand
    {
        private readonly ObservableCollection<Movie> _movies;
        private readonly ObservableCollection<string> _genres;

        public RefreshMoviesCommand(ObservableCollection<Movie> movies, ObservableCollection<string> genres)
        {
            _movies = movies;
            _genres = genres;
        }

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            var movies = Manager.Instance.GetNewValidMovies(_movies);

            foreach (var movie in movies)
            {
                _movies.Add(movie);
            }

            var genres = Manager.Instance.GetNewGenres(_genres);
            foreach (var genre in genres)
            {
                _genres.Add(genre);
            }
        }
    }
}
